<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: stats_keywords_all.php 114 2013-09-21 12:08:40Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 114 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 12:08:40 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

require('includes/application_top.php');
require(DIR_FS_INC.'inc.image_submit.php');
require_once(DIR_FS_INC.'inc.parse_input_field_data.php');

if($_POST['action'] == 'deletedb'){
	$db->db_query("DELETE FROM ".TABLE_SEARCH_QUERIES_ALL);
	$db->db_query("DELETE FROM ".TABLE_SEARCH_QUERIES_SORTED);
}

if($_POST['action'] == 'updatedb') {
	$keywords = $db->db_query("SELECT search_id, search_text, search_result FROM ".TABLE_SEARCH_QUERIES_ALL);
	$db->db_query("DELETE FROM ".TABLE_SEARCH_QUERIES_SORTED);
	
	while(!$keywords->EOF) {
		$update = $db->db_query("SELECT search_count AS total FROM ".TABLE_SEARCH_QUERIES_SORTED." WHERE search_text = ".$db->db_prepare($keywords->fields['search_text'])."");
		
		if($update->_numOfRows)
			$db->db_query("UPDATE ".TABLE_SEARCH_QUERIES_SORTED." SET search_count = ('".$update->fields['total']."' + 1), search_result = ".$db->db_prepare($keywords->fields['search_result']) ." WHERE search_text = ".$db->db_prepare($keywords->fields['search_text'])."");
		else
			$db->db_query("INSERT INTO ".TABLE_SEARCH_QUERIES_SORTED." (search_text, search_count, search_result) VALUES (".$db->db_prepare($keywords->fields['search_text']).", '1', '".$keywords->fields['search_result'] ."')");

		$db->db_query("DELETE FROM ".TABLE_SEARCH_QUERIES_SORTED." WHERE search_id = '".$keywords->fields['search_id']."' ");
		$keywords->MoveNext();
	}
}

if($_GET['widget'] == '1')
	header('Location: '.$_SERVER['HTTP_REFERER']);

require(DIR_WS_INCLUDES.'metatag.php');
?>
</head>
<body>
<?php require(DIR_WS_INCLUDES.'header.php'); ?>
<div id="wrapper">
<table class="outerTable" cellpadding="0" cellspacing="0">
  <tr>
    <td class="columnLeft2" width="<?php echo BOX_WIDTH; ?>" valign="top">
		<?php require(DIR_WS_INCLUDES.'column_left.php'); ?>
	</td>
    <td class="boxCenter" valign="top">
     <table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td>
          <table class="table_pageHeading" cellspacing="0" cellpadding="0" width="100%">
  			<tr>
		    	<td class="pageHeading" width="100%">
		    		<?php echo HEADING_TITLE ?>
		    	</td>
		  	</tr>
		</table></td>
        </tr>
        <tr>
        <td>
        <table border="0" width="100%" cellspacing="0" cellpadding="2">
          <tr>
		  <td valign="top">
		  <?php
			if(LOG_SEARCH_RESULTS == 'false')
				echo DESC_1;
		  ?>
          <table border="0" width="100%" cellspacing="0" cellpadding="2">
            <tr>
              <td width="1">
				<?php
					echo draw_form('delete', 'stats_keywords_all.php');
						echo draw_hidden_field('action','deletedb'); ?>
						<input type="submit" value="<?php echo CLEAR_DATABASE ?>" class="button" />
					</form>
			 </td>
			 <td width="1">
				<?php echo draw_form('update', 'stats_keywords_all.php');
					echo draw_hidden_field('action','updatedb').draw_hidden_field('page', ($_GET['page'] != '' ? $_GET['page'] : '1')); ?>
					<input type="submit" value="<?php echo UPDATE_DATABASE ?>" class="button" />
				</form>
			</td>
				 <td width="1"><a class="button" style="cursor:pointer" onclick="javascript:window.open('<?php echo href_link(FILENAME_STATS_KEYWORDS_ALL_PRINT); ?>', 'popup', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=500, height=600')"><?php echo PRINT_STATS ?></a>
			</td>
			<td>&nbsp;</td>
				</tr>
              </table></td>
            </tr>
            <tr>
            <td width="100%">
            <table width="100%" cellspacing="0" cellpadding="0" class="dataTable">
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_NUMBER; ?></td>
                <td class="dataTableHeadingContent" align="left"><?php echo TABLE_HEADING_SEARCH_TOTAL; ?></td>
                <td class="dataTableHeadingContent" align="left"><?php echo TABLE_HEADING_KEYWORD; ?></td>
                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRODUCTS_RETURNED; ?></td>
              </tr>
              <?php
				if($_GET['page'] > 1)
					$rows = ($_GET['page'] * '65' - '65');

  				$keywords_sorted = $db->db_query("SELECT search_text, search_count, search_result FROM ".TABLE_SEARCH_QUERIES_SORTED." ORDER BY search_count ASC");
  				while (!$keywords_sorted->EOF) { $rows++;
    				if (strlen($rows) < 2)
      					$rows = '0'.$rows;
					if ($rows % 2 == 0)
			    		$f = 'dataTableRow';
			    	else
			    		$f = '';
              		echo '<tr class="'.$f.'" onmouseover="this.className=\'dataTableRowOver\';" onmouseout="this.className=\''.$f.'\'">';
				?>
                <td><?php echo $rows; ?>.</td>
                <td>&nbsp;&nbsp;&nbsp;&nbsp; <?php echo $keywords_sorted->fields['search_count']; ?></td>
                <td>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $keywords_sorted->fields['search_text']; ?></td>
                <td><?php echo $keywords_sorted->fields['search_result']; ?></td>
                
				<?php $keywords_sorted->MoveNext();
  				} ?>
		</tr></table>
              </td>
			  </tr>
			  <tr><td><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr>
                <td class="smallText" valign="top"></td>
                <td class="smallText" align="right"></td>
              </tr>
            </table></td>
              </tr>
            </table>
            </td>
            </tr>
          </table>
          </td>
          </tr>
        </table>
      </table>
	</table>
</div>
<?php require(DIR_WS_INCLUDES.'footer.php'); ?>
</body>
</html>
<?php require(DIR_WS_INCLUDES.'application_bottom.php'); ?>